Page({
  data: {
    interviewHistory: []
  },

  onLoad: function() {
    const app = getApp();
    this.setData({
      interviewHistory: app.globalData.interviewHistory
    });
  },

  onShow: function() {
    const app = getApp();
    this.setData({
      interviewHistory: app.globalData.interviewHistory
    });
  },

  // 查看面试报告
  viewReport: function(e) {
    const timestamp = e.currentTarget.dataset.timestamp;
    wx.navigateTo({
      url: `/pages/report/report?timestamp=${timestamp}`
    });
  },

  // 清除历史记录
  clearHistory: function() {
    wx.showModal({
      title: '确认清除',
      content: '确定要清除所有面试历史记录吗？此操作不可恢复。',
      success: (res) => {
        if (res.confirm) {
          const app = getApp();
          app.globalData.interviewHistory = [];
          wx.setStorageSync('interviewHistory', []);
          
          this.setData({
            interviewHistory: []
          });
          
          wx.showToast({
            title: '已清除历史记录',
            icon: 'success'
          });
        }
      }
    });
  }
});
